/*  1:   */ package org.jetbrains.debugger.connection;
/*  2:   */ 
/*  3:   */

import com.intellij.ide.browsers.WebBrowser;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.util.Consumer;
import com.intellij.util.io.socketConnection.ConnectionStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.debugger.Vm;

import java.net.InetSocketAddress;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReference;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */
/* 16:   */
/* 17:   */ 
/* 18:   */ public abstract class ProcessBackedVmConnection
/* 19:   */   extends VmConnection<Vm>
/* 20:   */ {
/* 21:18 */   private final AtomicReference<Runnable> f = new AtomicReference();
/* 22:   */   
/* 23:   */   @Nullable
/* 24:   */   public WebBrowser getBrowser()
/* 25:   */   {
/* 26:23 */     return null;
/* 27:   */   }
/* 28:   */   
/* 29:   */   public abstract void createVmAndConnect(@NotNull InetSocketAddress paramInetSocketAddress, @NotNull AsyncResult<Vm> paramAsyncResult);
/* 30:   */   
/* 31:   */   public void open(@NotNull final InetSocketAddress paramInetSocketAddress)
/* 32:   */   {
/* 33:29 */     if (paramInetSocketAddress == null) {
/* 34:29 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/connection/ProcessBackedVmConnection", "open" }));
/* 35:   */     }
/* 36:29 */     setState(ConnectionStatus.WAITING_FOR_CONNECTION, "Connecting to " + paramInetSocketAddress.getHostName() + ":" + paramInetSocketAddress.getPort());
/* 37:30 */     final Future localFuture = ApplicationManager.getApplication().executeOnPooledThread(new Runnable()
/* 38:   */     {
/* 39:   */       public void run()
/* 40:   */       {
/* 41:33 */         if (Thread.interrupted()) {
/* 42:34 */           return;
/* 43:   */         }
/* 44:37 */         final AsyncResult localAsyncResult = new AsyncResult();
/* 45:38 */         ProcessBackedVmConnection.this.f.set(new Runnable()
/* 46:   */         {
/* 47:   */           public void run()
/* 48:   */           {
/* 49:41 */             localAsyncResult.reject("Closed explicitly");
/* 50:   */           }
/* 51:44 */         });
/* 52:45 */         ProcessBackedVmConnection.this.createVmAndConnect(paramInetSocketAddress, localAsyncResult);
/* 53:46 */         localAsyncResult.doWhenDone(new Consumer()
/* 54:   */         {
/* 55:   */           public void consume(@NotNull Vm paramAnonymous2Vm)
/* 56:   */           {
/* 57:49 */             if (paramAnonymous2Vm == null) {
/* 58:49 */               throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/connection/ProcessBackedVmConnection$1$4", "consume" }));
/* 59:   */             }
/* 60:49 */             ProcessBackedVmConnection.this.vm = paramAnonymous2Vm;
/* 61:50 */             ProcessBackedVmConnection.this.setState(ConnectionStatus.CONNECTED, "Connected to " + ProcessBackedVmConnection.1.this.val$address.getHostName() + ":" + ProcessBackedVmConnection.1.this.val$address.getPort());
/* 62:51 */             ProcessBackedVmConnection.this.startProcessing();
/* 63:   */           }
/* 64:51 */         }).doWhenRejected(new Consumer()
/* 65:   */         {
/* 66:   */           public void consume(String paramAnonymous2String)
/* 67:   */           {
/* 68:56 */             if (ProcessBackedVmConnection.this.getState().getStatus() == ConnectionStatus.WAITING_FOR_CONNECTION) {
/* 69:57 */               ProcessBackedVmConnection.this.setState(ConnectionStatus.CONNECTION_FAILED, paramAnonymous2String == null ? "Internal error" : paramAnonymous2String);
/* 70:   */             }
/* 71:   */           }
/* 72:57 */         }).doWhenProcessed(new Runnable()
/* 73:   */         {
/* 74:   */           public void run()
/* 75:   */           {
/* 76:63 */             ProcessBackedVmConnection.this.f.set(null);
/* 77:   */           }
/* 78:   */         });
/* 79:   */       }
/* 80:67 */     });
/* 81:68 */     this.f.set(new Runnable()
/* 82:   */     {
/* 83:   */       public void run()
/* 84:   */       {
/* 85:71 */         localFuture.cancel(true);
/* 86:   */       }
/* 87:   */     });
/* 88:   */   }
/* 89:   */   
/* 90:   */   public ActionCallback detachAndClose()
/* 91:   */   {
/* 92:   */     ActionCallback localActionCallback;
/* 93:   */     try
/* 94:   */     {
/* 95:80 */       Runnable localRunnable = (Runnable)this.f.getAndSet(null);
/* 96:81 */       if (localRunnable != null) {
/* 97:82 */         localRunnable.run();
/* 98:   */       }
/* 99:   */     }
/* :0:   */     finally
/* :1:   */     {
/* :2:86 */       localActionCallback = super.detachAndClose();
/* :3:   */     }
/* :4:88 */     return localActionCallback;
/* :5:   */   }
/* :6:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.debugger.connection.ProcessBackedVmConnection

 * JD-Core Version:    0.7.0.1

 */